package com.hxzy.service.impl;

import cn.hutool.crypto.digest.BCrypt;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.exception.WaimaiException;
import com.hxzy.dto.back.EmployeeSearchDTO;
import com.hxzy.dto.back.LoginDTO;
import com.hxzy.entity.Employee;
import com.hxzy.mapper.EmployeeMapper;
import com.hxzy.service.EmployeeService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 业务逻辑实现类
 * @Service 必须要加，代码交给框架来管理（业务逻辑）
 */
@Log4j2
@Service
public class EmployeeServiceImpl extends ServiceImpl<Employee, BigDecimal> implements EmployeeService {

    private EmployeeMapper  employeeMapper;

    /**
     * 交给spring框架自动装配需要的类
     * @param employeeMapper
     */
    @Autowired
    public void setEmployeeMapper(EmployeeMapper employeeMapper) {
        this.employeeMapper = employeeMapper;
        //不要忘记给父类赋值
        super.setMyBatisBaseDao(employeeMapper);
    }

    @Override
    public Employee login(LoginDTO loginDTO) {

        Employee dbEmployee = this.employeeMapper.findByLoginName(loginDTO.getLoginName());
        return dbEmployee;
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Override
    public List<Employee> search(EmployeeSearchDTO dto) {
        return this.employeeMapper.search(dto);
    }

    @Override
    public int selectLoginNameCount(String loginName) {
        return this.employeeMapper.selectLoginNameCount(loginName);
    }
}
